<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta charset="utf-8">
	<title>后台用户管理</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link rel="stylesheet" href="../../layui/css/layui.css" media="all">
	<style>
		.blogUser-con .layui-table-view {
			border: none;
		}
		
		.blogUser-con .layui-table-box {
			margin-top: 10px;
		}
		
		.blogUser-con {
			padding: 0 15px 15px 15px;
			margin-bottom:50px;
		}
		.blogUser-con  .layui-table-tool-self{
			display:none;
		}
		.blogUser-con .not_border_left {
			border-left: none !important;
		}
		
		.blogUser-con .blogUser dl dd.layui-this {
			background-color: #1E9FFF !important;
		}
		
		.blogUser-con .hide {
			display: none;
		}
		
		.blogUser-con .show {
			display: block;
		}
		
		.blogUser-con .btn_size {
			height: 28px !important;
			line-height: 28px !important;
		}
		
		.blogUser-con .layui-table-body table tbody .layui-table-hover {
			background: #fffdd3 !important;
		}
		
		.blogUser-con .layui-table-body table tbody .layui-table-click {
			background: #fdef9b !important;
		}
		
		.blogUser-con .layui-table, .layui-table-view {
			border: none;
			margin-top: 0;
		}
		
		#add-AdminUser {
			display: none;
			z-index: 999 !important;
		}
		
		#add-AdminUser .artTypeLayer {
			width: 90%;
			margin-left: auto;
			margin-right: auto;
			padding-top: 20px;
		}
		.adminuserdetail{
			padding:20px;
			display: none;
		}
		.adminuserdetail table tr td{
			padding: 15px;text-align: center;
		}
		.adminuserdetail .tdbck{
			background: #f2f2f2;
			width: 30%;
		}
	</style>
</head>
<body>

	<div class="blogUser-con">
		<blockquote class="layui-elem-quote not_border_left">
			<form class="layui-form" action="">
			  	<div class="layui-input-inline">
					<input type="text" name="queryrealname" id="queryrealname" placeholder="请输入查询内容" class="layui-input" autocomplete="off">
			    </div>
			    <div class="layui-inline">
	     	   		<button id="btnselfrontinfo" type="button" class="layui-btn layui-bg-blue">查询</button>
			    </div>
				<button type="button" class="layui-btn layui-bg-blue" id="addteacher" lay-event="addteacher" lay-filter="addteacher" style="margin-left: 10px;">添加</button>
			</form>
		</blockquote>

		<script type="text/html" id="barDemo">
			<a class="layui-btn layui-btn-xs" id="add" lay-event="add">报名</a>
			<a class="layui-btn layui-btn-xs" id="edit" lay-event="edit">编辑</a>
			<a class="layui-btn layui-btn-danger  layui-btn-xs" lay-event="delete">删除</a>
		</script>

		<!-- 表格开始 -->
		<table class="layui-hide" name="teacherinfo" id="teacherinfo" lay-filter="teacherinfo"></table>
		<!-- 表格结束 -->
		
	</div>
	<script src="../../js/jquery-3.3.1.js" charset="utf-8"></script>
	<script src="../../layui/layui.js" charset="utf-8"></script>
	<script src="../../js/loadselect.js" charset="utf-8"></script>
	<script>
	layui.use([ 'table', 'form', 'layer', 'laydate', 'laytpl', 'element' ], function() {
		var table = layui.table, form = layui.form, 
			layer = layui.layer, $ = layui.jquery,
			laydate = layui.laydate, laytpl = layui.laytpl,
			element = layui.element;
	
		
	//页面加载时加载学院信息
		querylist();
		
		/* 点击查询对学院信息进行筛选(模糊查询) */
		$("#btnselfrontinfo").click(function(){
			querylist();//调用局部刷新
			
		});
		
		function querylist(){
		
			var query = $("#queryrealname").val();
			/*加载表格*/
			table.render({
				elem : '#teacherinfo',
				id:'teacherinfo',
				url : '../../teacherinfo/getAllteacher?query=' + query,
				title : '教师管理数据表',
				height: "full-160",
				skin : 'line',
				even : true,
				cols : [ 
				     [ {field:'teacherid', title:'教师工号', sort: true, width:150}
				      ,{field:'teachername', title:'姓名',align : 'center'}
				      ,{field:'agend', title:'性别', width:80, templet:function(d){
				    		 return d.agend == "1" ? "男" : "女"},align : 'center'}
				      ,{field:'collegename', title:'所属分院', width:150,align : 'center'}
				      ,{field:'professionalname', title:'所属专业', width:200,align : 'center'}
				      ,{field:'unit', title:'单位',align : 'center'}
				      ,{field:'mobile', title:'电话号码',align : 'center'}
				      ,{title : '操作',toolbar : '#barDemo',align : 'center', width:210} 
				     ] 
				 ],
				 page: {
						layout: ['prev', 'page', 'next', 'skip', 'count', 'limit'],
						groups: 5,
						limit: 10,
						limits: [10, 20, 30, 40, 50],
						theme: '#1E9FFF',						
				 },
			});
			
		}
		
		
		/*
		 *添加操作
		*/
		$("#addteacher").click(function(){
			layer.open({
	          type: 2
	          ,title: '添加教师信息'
	          ,content: 'addteacher.jsp'
	          ,maxmin: true
	          ,area: ['500px', '550px']
	          ,btn: ['确定', '取消']
	          ,yes: function(index, layero){
	            //点击确认触发 iframe 内容中的按钮提交
		            var submit = layero.find('iframe').contents().find("#layuiadmin-app-form-submit");
		            submit.click();
	          }
	          
	        }); 
		})
		
		//监听工具条
		table.on('tool(teacherinfo)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
		  var data = obj.data; //获得当前行数据
		  var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
		  var tr = obj.tr; //获得当前行 tr 的DOM对象
		 
		 if(layEvent === 'add'){ //此处的add代表的是报名
		    //do something
		       //脚本编辑弹出层
	           var name = encodeURIComponent(data.toolName);
	           //alert(name);
	           layer.open({
	              type: 2,
	              title: '学生报名',
	              shadeClose: true,
	              shade: 0.5,
	              closeBtn:'1',//右上角xx关闭
	              area: ['400px','500px'],
	              content:'../signupmana/addsignup.jsp',
	              btn: ['确定', '取消'],
	              yes: function(index, layero){//后台执行成功是否都返回
	              	//点击确认触发 iframe 内容中的按钮提交，并且获取窗口id 并关闭
		            var submit = layero.find('iframe').contents().find("#layuiadmin-app-form-submit");
		            submit.click();
	              
		       	 },
	              success : function(layero, index){
		            var body = layui.layer.getChildFrame('body', index);
		            if(layEvent === 'add'){
		                // 取到弹出层里的元素，并把编辑的内容放进去
		                body.find("#athletesid").val(obj.data.teacherid);  //将选中的数据的id传到编辑页面的隐藏域，便于根据ID修改数据                
		                // 记得重新渲染表单
		                form.render();
		            }
		            setTimeout(function(){
		                layui.layer.tips('点击此处返回项目列表', '.layui-layer-setwin .layui-layer-close', {
		                    tips: 3
		                });
		            },100)
		        }
	         });
		    //同步更新缓存对应的值
		    obj.update({
		     
		    });
		  } else if(layEvent === 'delete'){ //删除
		     layer.confirm('真的删除行吗？', function(index){
			     
			      //向服务端发送删除指令
			      	$.post("../../teacherinfo/deleteteacher",{teacherid:obj.data.teacherid},function(flag){
		    			if(flag){
		    				layer.msg("刪除成功",{icon:6}); //表格刷新
					        table.reload('teacherinfo'); //重载表格
		    			}else{
		    				layer.msg("刪除失敗",{icon:5});
		    			}
		    			
			    	})
			  });
		  } else if(layEvent === 'edit'){ //编辑
		    //do something
		       //脚本编辑弹出层
	           var name = encodeURIComponent(data.toolName);
	           //alert(name);
	           layer.open({
	              type: 2,
	              title: '修改教师信息',
	              shadeClose: true,
	              shade: 0.5,
	              closeBtn:'1',//右上角xx关闭
	              area: ['500px','550px'],
	              content:'modteacher.jsp',
	              btn: ['确定', '取消'],
	              yes: function(index, layero){
	              
		            //点击确认触发 iframe 内容中的按钮提交
		            var submit = layero.find('iframe').contents().find("#layuiadmin-app-form-submit");
		            submit.click();
		        },
	              success : function(layero, index){
		            var body = layui.layer.getChildFrame('body', index);
		            if(layEvent === 'edit'){
		                // 取到弹出层里的元素，并把编辑的内容放进去
		                body.find("#teacherid").val(obj.data.teacherid);  //将选中的数据的id传到编辑页面的隐藏域，便于根据ID修改数据
		                body.find("#teachername").val(obj.data.teachername); 
		                body.find("#agend").val(obj.data.agend);  
		                body.find("#mobile").val(obj.data.mobile); 
		                body.find("#unit").val(obj.data.unit);
		                body.find("#professionalname").val(obj.data.professionalname);          
		                body.find("#note").val(obj.data.note);  //会员等级，注意：这里我只把等级ID放到弹出层页面的隐藏域，然后再使用ajax查询等级列表，动态生成下拉列表
		              
		                // 记得重新渲染表单
		                form.render();
		            }
		            setTimeout(function(){
		                layui.layer.tips('点击此处返回项目列表', '.layui-layer-setwin .layui-layer-close', {
		                    tips: 3
		                });
		            },100)
		        }
	         });
		    //同步更新缓存对应的值
		    obj.update({
		      
		    });
		  }
		});
		
});
	
	</script>
</body>
</html>